import { _decorator, Component, director, Node } from 'cc';
const { ccclass, property } = _decorator;

export enum Page {
    /**'开始页'*/
    MAIN,
    /**'加载页' */
    LODING
}

@ccclass('Index')
export class Index extends Component {
    @property({ type: Node })
    Main: Node | null;//需要挂载节点
    @property({ type: Node })
    Loding: Node | null;

    start() {
        Index.I = this;
        Index.ShowPage(Page.MAIN);
    }

    private static I: Index;
    /**切换节点显示 */
    static ShowPage(key: Page) {
        const arr = [
            {
                key: Page.MAIN,
                value: this.I.Main,
            },
            {
                key: Page.LODING,
                value: this.I.Loding,
            }
        ];
        //如果为false就是从另外一个场景调用的此方法
        if (arr.every(item => item.value !== null)) {
            arr.forEach(item => {
                if (key === item.key) {
                    item.value.active = true;
                } else {
                    item.value.active = false;
                }
            });
        } else {
            director.loadScene('index');
        }
    }
}


